/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-09-22
 * Time: 13:09
 */
//线程安全
class Counter{
    public  int count=0;
    private Object locker=new Object();
    public synchronized void  increase(){
        synchronized(locker){
            count++;
        }
    }
    public synchronized void increase1(){
            count++;
    }
}
public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
    Counter counter=new Counter();
    Thread t1=new Thread(() ->{
        for (int i = 0; i <5000; i++) {
            counter.increase();
        }
    });
    Thread t2=new Thread(() ->{
        for (int i = 0; i <5000; i++) {
            counter.increase1();
        }
    });
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    System.out.println(counter.count);
    }
}
